<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="../css/api.css" />
    <link rel="stylesheet" type="text/css" href="../css/aui.css" />
    <style type="text/css">
        .class-title {
            margin-top: 10px;
            margin-left: 10px;
            margin-right: 10px;
            font-size: 20px;
            font-weight: bold;
            color: #00BFFF;
        }

        .class-hr {
            margin-top: 5px;
            height: 1px;
            border: none;
            border-top: 1px solid #DCDCDC;
        }

        .class-seqno {
            margin-top: 3px;
            margin-left: 10px;
            margin-right: 25px;
            font-size: 10px;
            color: #808080;
            font-weight: bold;
            text-align: right;
        }

        .class-table {
            width: 100%;
            text-align: left;
            color: black;
            font-size: 13px;
            margin-left: 2%;
            width: 100%;
            table-layout: fixed;
        }

        .class-td {
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }

        .lw {
            background-color: #DCE9F2;
            border-top: 1px solid #CBD6DE;
            border-bottom: 1px solid #ADBECB;
            color: #467aa7;
            font-size: 12px;
            font-weight: bold;
        }

        .lw1 {
            background-color: #f0f5f5;
            border-top: 1px solid #CBD6DE;
            border-bottom: 1px solid #ADBECB;
            color: #467aa7;
            font-size: 12px;
        }

        .table {
            margin-bottom: 15px;
            width: 100%;
            border-collapse: collapse;
            font-size: 13px;
            margin-bottom: 15px;
            width: 100%;
            border-collapse: collapse;
        }

        .table td {
            height: 40px;
            text-align: left;
            border: 0px solid #CBD6DE;
            padding: 0;
            margin: 0;
        }
    </style>
</head>

<body>
    <div class="aui-content aui-margin-b-15">
        <ul class="aui-list aui-form-list">
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">创建日期起</div>
                    <div class="aui-list-item-input" onclick="timePicker('dateStart');">
                        <input type="text" placeholder="选择日期" class="aui-input" id="dateStart">
                    </div>
                </div>
            </li>
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">创建日期止</div>
                    <div class="aui-list-item-input" onclick="timePicker('dateEnd');">
                        <input type="text" placeholder="选择日期" class="aui-input" id="dateEnd">
                    </div>
                </div>
            </li>
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">异常类型</div>
                    <div class="aui-list-item-input">
                        <select id="exceptionTypeGid">
                        </select>
                    </div>
                </div>
            </li>
        </ul>
        <div style="width:100%;margin-top:2%;"></div>
        <div class="aui-btn aui-btn-info aui-btn-block" onclick="searchData()">查询</div>
        <div id="divhtml" style="display: block;width:100%;height: 490px;overflow-y: scroll;"></div>

        <script id="detailTemp" type="text/x-dot-template">

            {{~ it:value:index}}
            <div class="aui-dialog-header">异常详情</div>
            <div class="aui-dialog-body">
                <div style="background-color:white;">
                    <table class="table" style='width:100%;'>
                        <tr>
                            <td width='20%' algin='center' class="lw">响应人</td>
                            <td width='20%' algin='center' class="lw1">{{= it[index].responseId }}</td>
                            <td width='20%' algin='center' class="lw">响应时间</td>
                            <td width='40%' algin='center' class="lw1">{{= it[index].responseDate }}</td>
                        </tr>
                        <tr>
                            <td width='20%' algin='center' class="lw">处理人</td>
                            <td width='20%' algin='center' class="lw1">{{= it[index].exhandlId }}</td>
                            <td width='20%' algin='center' class="lw">处理时间</td>
                            <td width='40%' algin='center' class="lw1">{{= it[index].exhandlDate }}</td>
                        </tr>
                        <tr>
                            <td width='20%' algin='center' class="lw">处理措施</td>
                            <td width='20%' algin='center' class="lw1">{{= it[index].exMeasureName }}</td>
                            <td width='20%' algin='center' class="lw">处理备注</td>
                            <td width='40%' algin='center' class="lw1">{{= it[index].exhandlRemark }}</td>
                        </tr>
                        <tr>
                            <td width='20%' algin='center' class="lw">关闭人</td>
                            <td width='20%' algin='center' class="lw1">{{= it[index].excolseId }}</td>
                            <td width='20%' algin='center' class="lw">关闭时间</td>
                            <td width='40%' algin='center' class="lw1">{{= it[index].excolseDate }}</td>
                        </tr>
                        <tr>
                            <td width='20%' algin='center' class="lw">异常原因</td>
                            <td width='20%' algin='center' class="lw1">{{= it[index].exReasonName }}</td>
                            <td width='20%' algin='center' class="lw">关闭备注</td>
                            <td width='40%' algin='center' class="lw1">{{= it[index].excolseRemark }}</td>
                        </tr>
                    </table>
                </div>
            </div>
            <div class="aui-dialog-footer">
                <div class="aui-dialog-btn aui-text-info" tapmode onclick="confirm()">关闭</div>
            </div>
            {{~}}

        </script>
        <div class="aui-dialog aui-hidden" id="dialog">

        </div>
    </div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/doT.min.js"></script>
<script type="text/javascript" src="../script/public.js"></script>
<script type="text/javascript" src="../script/jquery-1.8.2.min.js"></script>
<script type="text/javascript">
    //初始化
    apiready = function () {

        //初始化当前日期
        crateDate();

        //查询生产线下拉框
        getCombox();

        searchData();
    }

    //获取当前日期
    function crateDate() {
        var date = new Date();
        var year = date.getFullYear();
        var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
        var day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
        $("#dateStart").val(year + "-" + month + "-" + day);
        $("#dateEnd").val(year + "-" + month + "-" + day);


    }

    //时间选择器
    function timePicker(id) {
        api.openPicker({
            type: 'date',
            date: new Date(),
            title: '选择日期'
        }, function (ret, err) {
            if (ret) {
                var monthTemp = (ret.month < 10 ? '0' + ret.month : ret.month);
                var dayTemp = (ret.day < 10 ? '0' + ret.day : ret.day);
                var date = ret.year + "-" + monthTemp + "-" + dayTemp;
                $("#" + id).val(date);
            }
        });
    }

    //查询下拉框(看板状态，看板类型，数量状态)
    function getCombox() {
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getUtilComboxList";
        var data = {
            values: {
                tablename: "usm_exception_type",
                column_name: "name",
                column_value: "sysid",
                condition: "is_delete=0",
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var map = eval("(" + data + ")");
                var list = eval(map.list);
                var html = "";
                for (var i = 0; i < list.length; i++) {
                    html += "<option value='" + list[i].value + "'>" + list[i].label + "</option>";
                }
                $api.html($api.byId("exceptionTypeGid"), html);
            }
        });
    }

    //查询表格数据
    function searchData() {
        //创建日期起
        var dateStart = $("#dateStart").val();
        //创建日期止
        var dateEnd = $("#dateEnd").val();
        //异常类型
        var exceptionTypeGid = $("#exceptionTypeGid").val();

        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/usmExceptionBillHistory";
        var data = {
            values: {
                dateStart: dateStart,
                dateEnd: dateEnd,
                exceptionTypeGid: exceptionTypeGid,
                un: un,
            }
        };

        api.showProgress({
            title: '查询中...',
        });
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                api.hideProgress();

                if (myobj.code == '0') {

                    var list = eval(myobj.list);

                    var html = "<div class='class-title'>";
                    html += "<span>总数:" + list.length + "</span>";
                    html += "<hr class='class-hr' />";
                    html += "</div>";
                    //遍历
                    for (var i = 0; i < list.length; i++) {
                        //序号
                        html += "<div class='class-seqno'>";
                        html += "<span>" + (i + 1) + "</span>";
                        html += "</div>";
                        //表格
                        html += "<div style='margin-left:10px;margin-right:15px;'>";
                        html += "<table class='class-table'>";
                        html += "<tr>";
                        html += "<td class='class-td' style='width:60%'></td>";
                        html += "<td class='class-td' style='width:40%'></td>";
                        html += "</tr>";
                        html += "<tr>";
                        html += "<td colspan='2' class='class-td' >记录编码:" + list[i].code + "</td>";
                        html += "</tr>";
                        html += "<tr>";
                        html += "<td class='class-td'>异常类型:" + list[i].exceptionTypeName + "</td>";
                        html += "<td class='class-td'>异常内容:" + list[i].exceptionContentName + "</td>";
                        html += "</tr>";
                        html += "<tr>";
                        html += "<td class='class-td'>物料号:" + list[i].mrlCode + "</td>";
                        html += "<td class='class-td'>工序号:" + list[i].opCode + "</td>";
                        html += "</tr>";
                        html += "<tr>";
                        html += "<td class='class-td'>设备编码:" + list[i].ext03 + "</td>";
                        html += "<td class='class-td'>产线编码:" + list[i].ext04 + "</td>";
                        html += "</tr>";
                        html += "<tr>";
                        html += "<td class='class-td'>发起时间:" + list[i].launchDate + "</td>";
                        html += "<td class='class-td'>发起人:" + list[i].launchId + "</td>";
                        html += "</tr>";
                        html += "<tr>";
                        html += "<td  class='class-td'>任务节点:";
                        if (list[i].state != "8") {
                            html += "<span style='color:red'>" + list[i].nodeState + "</span>";
                        } else {
                            html += "<span>已关闭</span>";
                        }
                        html += "<td class='class-td'><div class='aui-btn aui-btn-info' onclick='searchDetail(\"" + list[i].sysid + "\")'>异常详情</div></td>";
                        html += "</td>";
                        html += "</tr>";
                        html += "</table>";
                        html += "<hr class='class-hr' />";
                        html += "</div>";
                    }

                    $api.html($api.byId("divhtml"), html);

                } else {
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }

            } else {
                api.hideProgress();
                alert(JSON.stringify(err));
            }
        });
    }

    //任务详情
    function searchDetail(sysid) {

        var serverUrl = localStorage.getItem('serverUrl');
        var un = localStorage.getItem('un');
        var url = serverUrl + "/app/usmExceptionBillHistoryDetail";
        var data = {
            values: {
                sysid: sysid,
                un: un,
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                if (myobj.code == '0') {

                    var mydata = eval(myobj.list);
                    $api.append($api.dom("body"), '<div class="aui-mask"></div>');
                    $api.removeCls($api.dom(".aui-dialog.aui-hidden"), "aui-hidden");
                    var evaluation = doT.template($api.dom('#detailTemp').innerHTML);
                    $api.dom('#dialog').innerHTML = evaluation(mydata);

                } else {
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            }
        });
    }

    //异常详情关闭
    function confirm() {
        $api.remove($api.dom(".aui-mask"));
        $api.addCls($api.dom(".aui-dialog"), "aui-hidden");
    }

    //返回按钮
    function closeWin() {
        api.closeWin({});
    }
</script>

</html>